package com.example.a33mvvm.home;

import androidx.lifecycle.MutableLiveData;

import com.example.base_mvvm.base.BaseRepo;
import com.example.base_mvvm.entity.BannerEntity;
import com.example.base_mvvm.entity.HomeVideoEntity;
import com.example.base_mvvm.entity.LikeEntity;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class BannerRepo extends BaseRepo {
    public void banner(MutableLiveData<BannerEntity> success, MutableLiveData<String> failure){
        apiService.banner()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BannerEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BannerEntity bannerEntity) {
                            success.setValue(bannerEntity);
                    }

                    @Override
                    public void onError(Throwable e) {
                         failure.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void video(int page, int size, MutableLiveData<HomeVideoEntity> success, MutableLiveData<String> failure){
        apiService.homeVideo(page,size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<HomeVideoEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(HomeVideoEntity homeVideoEntity) {
                        success.setValue(homeVideoEntity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failure.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void like(int id, MutableLiveData<LikeEntity> success, MutableLiveData<String> failure){
        apiService.like(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<LikeEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(LikeEntity likeEntity) {
                        success.setValue(likeEntity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failure.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void disLike(int id, MutableLiveData<LikeEntity>success, MutableLiveData<String> failure){
        apiService.disLike(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<LikeEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(LikeEntity disLikeEntity) {
                        success.setValue(disLikeEntity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failure.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
